package com.practice;

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Hello world!
 *
 */
public class App 
{
    private static AtomicInteger aliveCounter = new AtomicInteger(0);

    App() {
        aliveCounter.incrementAndGet();
    }

    @Override
    protected void finalize() throws Throwable {
        App.aliveCounter.decrementAndGet();
    }

    public static void main(String[] args )
    {
        ArrayList<App> al = new ArrayList<>(10000);

        for(int i =0;;i++){
            App  f = new App();
            al.add(f);
            if((i%100_000)==0){
                System.out.format("After creating %d objects, %d are still alive. %n",new Object[]{i,App.aliveCounter.get()});
            }
        }
    }
}
